<?php
/**
 * User: 鬼一浪人
 * DateTime: 2019/11/11 16:43
 * Description:
 */
namespace App\Services;

class BKDRhash
{
    // 31 131 1313 13131 131313 etc..
    const SEED = 1313;

    /**
     *
     * @param $string
     * @return int
     */
    public static function hashToInt($string)
    {
        $seed = self::SEED;
        $hash = 0;

        $len = strlen($string);

        for($i = 0; $i < $len; $i++) {
            $hash = ((floatval($hash * $seed) & 0x7FFFFFFF) + ord($string[$i])) & 0x7FFFFFFF;
        }
        return ($hash & 0x7FFFFFFF);
    }
}
